﻿using System;
using System.Configuration;
using System.ServiceModel.Configuration;
using WcfExtensions.ServiceModel.Channels;
using WcfExtensions.ServiceModel.Description;

namespace WcfExtensions.ServiceModel.Configuration
{
    public class CompressionBehaviorExtensionElement : BehaviorExtensionElement
    {
        private const string AlgorithmName = "algorithm";
        private const string LevelName = "level";

        protected override object CreateBehavior()
        {
            return new CompressionBehavior(Algorithm, Level);
        }

        public override Type BehaviorType
        {
            get
            {
                return typeof(CompressionBehavior);
            }
        }


        [ConfigurationProperty(LevelName, DefaultValue = CompressionLevel.Normal)]
        public CompressionLevel Level
        {
            get { return (CompressionLevel)base[LevelName]; }
            set { base[LevelName] = value; }
        }

        [ConfigurationProperty(AlgorithmName, DefaultValue = CompressionAlgorithm.GZip)]
        public CompressionAlgorithm Algorithm
        {
            get { return (CompressionAlgorithm)base[AlgorithmName]; }
            set { base[AlgorithmName] = value; }
        }

    }
}